/*
 * Copyright (c) 2006, 2021, webrx.cn All rights reserved.
 *
 */
package cn.webrx;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>Project: javaseapp - List1
 * <p>Powered by webrx On 2021-08-09 14:47:51
 * <p>Created by IntelliJ IDEA
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 16
 */
public class List1 {
    public static void main(String[] args) {

        //Collection 接口
        // List4 接口
        // Set  接口
        List list = new ArrayList();
        list.add("java");
        list.add(0, "php");
        list.add(2, "javascript");
        list.addAll(0, List.of("java1", "java2", "java3"));

        System.out.println(list.get(0));
        System.out.println(list.get(1));
        System.out.println(list.get(2));
        //返回list容器的元素个数
        System.out.println(list.size());
        //删除清空所有元素
        //list.clear();
        //list.remove("php");
        //list.remove(0);
        list.add(2, "python");
        list.add(2, "my-java 16");
        //list.removeAll(List4.of("java2", "java3"));
        //list.removeIf(e -> true);
        //list.removeIf(a -> a.toString().startsWith("java"));

        //判断检查
        System.out.println(list.contains("java8"));//false
        System.out.println(list.isEmpty());//false

        System.out.println(list.indexOf("java"));
        System.out.println(list.lastIndexOf("java"));
        //复制出子List
        System.out.println(list.subList(1, 3));

        System.out.println(list);
        //遍历list 方法一
        for (Object o : list) {
            System.out.println(o);
        }
        //方法二
        for (int i = 0; i < list.size(); i++) {
            System.out.print(list.get(i));
        }
        System.out.println();
        //方法三 lambda 表达式
        //list.forEach(System.out::println);
        list.forEach(System.out::print);


    }
}
